﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json.Converters;
using System.IO;

namespace ALiteTeam.PackageTracer.Data
{
    [JsonObject]
    public class QueryResult
    {
        /// <summary>
        /// 把Json字符串转换为实体对象
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static QueryResult ParseOrder(string context)
        {
            QueryResult result;

            var reader = new StringReader(context);
            var serializer = new JsonSerializer();
            result = serializer.Deserialize(reader, typeof(QueryResult)) as QueryResult;

            return result;  
        }

        [JsonProperty(PropertyName = "nu")]
        public string OrderNo { get; set; }

        [JsonProperty(PropertyName = "message")]
        public string Summary { get; set; }

        [JsonProperty(PropertyName = "status")]
        public byte Status { get; set; }

        [JsonProperty(PropertyName = "link")]
        public string Link { get; set; }

        [JsonProperty(PropertyName = "Data")]
        public List<Detail> Details { get; set; }

        [JsonObject]
        public class Detail
        {
            [JsonProperty(PropertyName = "time")]
            [JsonConverter(typeof(IsoDateTimeConverter))]
            public DateTime Time { get; set; }

            [JsonProperty(PropertyName = "context")]
            public string Context { get; set; }

            [JsonProperty(PropertyName = "ftime")]
            [JsonConverter(typeof(IsoDateTimeConverter))]
            public DateTime FTime { get; set; }
        }
    }
}
